<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { queryAllAttachment } from '/@/api/org/file-attachment'
import { reactive } from 'vue'
const attachmentTableRef = ref()
const props = defineProps({
    height: {
        type: Number
    },
    queryParams: {
        type: Object,
        require: true
    }
})

const attachmentTableState = reactive({
    loadData: (params: any) => {
        return queryAllAttachment({ ...params, ...props.queryParams })
    },
    tableColumn: [
        { label: '序号', width: '50', type: 'index' },
        {
            prop: "fileName", label: "文件名", showOverflowTooltip: true,
            align: 'left',
            type: 'link', linkClick: (row: any) => {
                // router.push({ path: '/standard/SdQualitycardService/form/' + row.qualitycardId })
            }
        },
        { prop: "filetype", label: '类型', width: '150' },
        { prop: "filesize", label: '大小', width: '150', slot: 'size' },
        { prop: "createTime", label: '上传时间', width: '350' },

    ]
})
defineExpose({
    getAttachmentTableRef: () => attachmentTableRef.value
})

/**
     * 格式化文件大小
     * @param {*} value
     */
const formatFileSize = (row: any) => {
    let value = Number(row.filesize)
    if (row.filesize && !isNaN(value)) {
        const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB', 'BB']
        let index = 0
        let k = value
        if (value >= 1024) {
            while (k > 1024) {
                k = k / 1024
                index++
            }
        }
        return `${(k).toFixed(2)}${units[index]}`
    }
    return '-'
}



</script>
<template>
    <jxtech-page-table
        :table-height="props.height"
        row-key="uuid"
        ref="attachmentTableRef"
        :page-size="25"
        :table-column="attachmentTableState.tableColumn"
        :load-data="attachmentTableState.loadData"
    >
        <template #size="{ row }">{{ formatFileSize(row) }}</template>
    </jxtech-page-table>
</template>
<style lang="scss" scoped>
</style>